<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta charset="UTF-8">
<title>失物招领后台管理</title>
<script type="text/javascript" src="../js/jquery.js"></script>
<script src="../js/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" href="../css/bootstrap.css" />
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/main.css" />
<script type="text/javascript" src="../js/bootstrap.js"></script>
<script type="text/javascript" src="../js/scrollspy.js"></script>
<link href="../fonts/css/font-awesome.css" rel="stylesheet">

<!-- Toastr style -->
<link href="../css/toastr.min.css" rel="stylesheet">

<link href="../css/animate.css" rel="stylesheet">
<link href="../css/style.css" rel="stylesheet">
<!--sweetalert-->
<link rel="stylesheet" href="../css/sweetalert.css" />
</head>

<body>
	<div id="wrapper">
		<!--左侧导航栏-->
		<nav class="navbar-default navbar-static-side" role="navigation">
		<div class="sidebar-collapse">
			<ul class="nav metismenu" id="side-menu">
				<li><a href="#"><i class="fa fa-th-large"></i> <span
						class="nav-label">发帖管理</span> <span class="fa arrow"></span></a>
					<ul class="nav nav-second-level collapse">
						<li><a href="findingadmin.jsp">寻帖审核</a></li>
						<li><a href="main.jsp">失物审核</a></li>
					</ul></li>
				<li><a href="#"><i class="fa fa-th-large"></i> <span
						class="nav-label">信息管理</span> <span class="fa arrow"></span></a>
					<ul class="nav nav-second-level collapse">
						<li><a href="locationadmin.jsp">招领点管理</a></li>
						<li><a href="charts.jsp">图表展示</a></li>
						
					</ul></li>
				<li>
							<a href="#"><i class="fa fa-th-large"></i> <span class="nav-label">管理</span> <span class="fa arrow"></span></a>
							<ul class="nav nav-second-level collapse">
								<li>
									<a href="editor.jsp">发布公告</a>
								</li>
								<li>
									<a href="data.jsp">数据备份</a>
								</li>
							</ul>
						</li>
			</ul>

		</div>
		</nav>
		<!--
            	作者：1462859532@qq.com
            	时间：2017-03-29
            	描述：右侧导航栏
            -->
		<div id="page-wrapper" class="gray-bg">
			<div class="row border-bottom">
				<nav class="navbar navbar-static-top" role="navigation"
					style="margin-bottom: 0">
				<div class="navbar-header">
					<a class="navbar-minimalize minimalize-styl-2 btn btn-primary "
						href="#"><i class="fa fa-bars"></i> </a>
				</div>
				<ul class="nav navbar-top-links navbar-right">
					<li><span class="m-r-sm text-muted welcome-message">欢迎来到系统管理员</span>
					</li>
					<li><a href="login.jsp"> <i class="fa fa-sign-out"></i> 注销
					</a></li>
				</ul>
				</nav>
			</div>
			<div class="row wrapper border-bottom white-bg page-heading">
				<div class="col-lg-10">
				
					<ol class="breadcrumb">
						<li><a>地点</a></li>
						<li class="active"><strong>暂存地点</strong></li>
					</ol>
				</div>
				<div class="col-lg-2"></div>
			</div>

			<div class="wrapper wrapper-content  animated fadeInRight article">

				<div class="row">

					<!--失物信息-->
					<div class="col-md-12">
						<div>
							<div class="pull-right">
								<a href="#" id="addloc" class="login dropdown-toggle"
									data-toggle="modal" data-target="#modeladd"
									style="margin-right: 20px;">新增 </a>
							</div>
						</div>
						<div class="losingadmin panel panel-default">
							<div class="panel-body">
								<table class="losingtable table table-striped"
									cellpadding="20px" cellspacing="5" id="losingshow">
									<thead>
										<tr class="active">
											<th style="width: 25%">名称</th>
											<th style="width: 25%">地点</th>
											<th style="width: 25%">联系电话</th>
											<th style="width: 25%">操作</th>
										</tr>
									</thead>
									<tbody id="locappend">

									</tbody>
								</table>
							</div>


						</div>
					</div>
				</div>
			</div>
		</div>

	</div>
	<div class="footer">
		<div>
			<strong>Copyright</strong>版权所有 &copy; 2017
		</div>
	</div>
<div>
	<div class="modal fade" id="modeladd" tabindex="-1" role="dialog">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">招领点新增</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<!--
                                	作者：1462859532@qq.com
                                	时间：2017-03-28
                                	描述：可以在上面做个表单验证
                                -->
						<label for="locname" class="control-label">名称</label> <input
							type="text" name="" id="locname" class="form-control" value=""
							required="required" pattern="" title="">
					</div>
					<div class="form-group">
						<label for="area" class="control-label">地区</label> <input
							type="text" class="form-control" id="area" placeholder="地区">
					</div>
					<div class="form-group">
						<label for="phone" class="control-label">联系电话</label> <input
							type="text" class="form-control" id="phone" placeholder="联系电话">
					</div>
				</div>
				<div class="modal-footer">

					<button type="button" class="btn btn-default" id="addclose"
						data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" id="sure"
						data-dismiss="modal">确定</button>
				</div>
			</div>
		</div>
	</div>
</div>
	<!--模态框关闭-->

	<!-- Mainly scripts -->
	<script src="../js/jquery.js"></script>
	<script src="../js/bootstrap.min.js"></script>
	<script src="../js/jquery.metisMenu.js"></script>
	<script src="../js/jquery.slimscroll.min.js"></script>

	<!-- Custom and plugin javascript -->
	<script src="../js/inspinia.js"></script>
	<script src="../js/pace.min.js"></script>
	<script type="text/javascript" src="../js/sweetalert.min.js"></script>
	<script>
			$(function() {
				$.ajax({
					type:"post",
					url:"../admin/allloc.action",
					dataType:"json",
					success:function(data){
						for(var i=0;i<data.length;i++){
							$("#locappend").append('<tr><td style="display: none;">'+
		    						  data[i].locid+'</td><td>'+
		    						  data[i].locname+'</td><td>'+
		    						  data[i].locationaddress+'</td><td>'+
		    						  data[i].locphone+'</td>'+
		    						  '<td><a href="#" class="btn btn-primary agree" data-toggle="modal" data-target="#modeladd" onclick="agree(this)">修改</a>'+
		    						  '</td></tr>');
						}
					}
				})
				
				$("#sure").click(function(){
					setTimeout(function(){
						if($("#locname").val()==""||$("#area").val()==""||$("#phone").val()==""){
							swal("失败","信息需要全部填写","error");
						}
						if(tempid!=null){
							//修改信息
							$.ajax({
								type:"post",
								url:"../admin/updateloc.action",
								dataType:"json",
								data:{"locid":tempid,"locname":$("#locname").val(),"locationaddress":$("#area").val(),"locphone":$("#phone").val()},
								success:function(data){
									if(data==0){
										swal("失败","修改失败","error");
										tempid=null;
									}else{
										swal("成功","修改成功","success");
										tempid=null;
										window.location.href="../admin/locationadmin.jsp";
									}
								}
							})
						}else{
							//添加
							$.ajax({
								type:"post",
								url:"../admin/insertloc.action",
								dataType:"json",
								data:{"locname":$("#locname").val(),"locationaddress":$("#area").val(),"locphone":$("#phone").val()},
								success:function(data){
									if(data==0){
										swal("失败","添加失败","error");
										tempid=null;
									}else{
										swal("成功","添加成功","success");
										tempid=null;
										window.location.href="../admin/locationadmin.jsp";
									}
								}
							})
						}
					},1000)				
				});
				
				
			})
			var tempid=null;
			function agree(e){
				 var id=$(e).parent().parent().children(":first").text();
				 tempid=id;
				 $.ajax({
					 type:"post",
						url:"../admin/querylocbyid.action?id="+id,
						dataType:"json",
						success:function(data){
							$("#locname").val(data.locname);
							$("#area").val(data.locationaddress);
							$("#phone").val(data.locphone);
						}
				 })
				 
			}
			
			
			
			$("#addloc").click(function(){
				$("#locname").val("");
				$("#area").val("");
				$("#phone").val("");
			})
		</script>
</body>

</html>